package com.base.action;

import java.util.List;
import java.util.Map;

import com.common.bean.Department;
import com.common.util.PagerModel;
import com.opensymphony.xwork2.Preparable;

public class DepartmentAction extends AbstractDepartmentAction implements Preparable{
	private static final long serialVersionUID = 1L;

	private Department department;
	
	private String supdept;
	
	private List<Department> deptlist;
	
	private List<Map> deptMap;
	
	private PagerModel pm;
	
	private String deptcode;
	
	private List deptcodelist;
	
	private String deptcaption;
	
	private int offset;
	
	@SuppressWarnings("unchecked")
	public void prepare() throws Exception {
		deptlist = departmentService.findAllDepartment();
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public String execute() throws Exception {
		return SUCCESS;
	}
	
	public String doCreate() {
		departmentService.addDepartment(department , supdept);
		return SUCCESS;
	}
	
	@SuppressWarnings("unchecked")
	public String listDept() {
		pm = departmentService.findAllDept(deptcode);
		return SUCCESS;
	}
	
	public String findDeptByDeptcaption() throws Exception {
		pm = departmentService.findDeptByDeptcaption(deptcaption);
		return SUCCESS;
	}
	
	public String removeDept() throws Exception {
		departmentService.removeDepartment(deptcode);
		return SUCCESS;
	}
	
	@SuppressWarnings("unchecked")
	public String removeDeptlist() throws Exception {
		for(String deptcode_s:(List<String>)deptcodelist) {//这是个BUG
			departmentService.removeDepartment(deptcode_s);//级联删除有数据库维护
		}
		
		return SUCCESS;
	}
	
	public String findTreeMap()	{
		deptMap = departmentService.findAllDeptMap();
		return SUCCESS;
	}

	public Department getDepartment() {
		return department;
	}

	public void setDepartment(Department department) {
		this.department = department;
	}

	public List<Department> getDeptlist() {
		return deptlist;
	}

	public void setDeptlist(List<Department> deptlist) {
		this.deptlist = deptlist;
	}

	public String getSupdept() {
		return supdept;
	}

	public void setSupdept(String supdept) {
		this.supdept = supdept;
	}

	public String getDeptcode() {
		return deptcode;
	}

	public void setDeptcode(String deptcode) {
		this.deptcode = deptcode;
	}

	public PagerModel getPm() {
		return pm;
	}

	public void setPm(PagerModel pm) {
		this.pm = pm;
	}
	
	public int getOffset() {
		return offset;
	}

	public void setOffset(int offset) {
		this.offset = offset;
	}

	public List<Map> getDeptMap() {
		return deptMap;
	}

	public void setDeptMap(List<Map> deptMap) {
		this.deptMap = deptMap;
	}

	public String getDeptcaption() {
		return deptcaption;
	}

	public void setDeptcaption(String deptcaption) {
		this.deptcaption = deptcaption;
	}

	public List getDeptcodelist() {
		return deptcodelist;
	}

	public void setDeptcodelist(List deptcodelist) {
		this.deptcodelist = deptcodelist;
	}
	
}
